let id = 1
export default class Dep{
    constructor(){
       this.id = id++
       this.subs = []
    }
    depend(){
     if(Dep.target){
        Dep.target.addDep(this)
     }
    }
    addSub(watcher){
      this.subs.push(watcher)
    }
    notify(){
      this.subs.forEach((w)=>{
        w.update()
      }) 
    }
}

Dep.target = null
const watchers = []
export function pushTarget(watcher){
    Dep.target = watcher
    watchers.push(watcher)
}

export function popTarget(){
    watchers.pop()
    Dep.target = watchers[watchers.length - 1]
}